package com.ruoyi.module.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.module.domain.ExamWrong;
import com.ruoyi.module.mapper.ExamWrongMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.module.mapper.ExamFractionMapper;
import com.ruoyi.module.domain.ExamFraction;
import com.ruoyi.module.service.IExamFractionService;

/**
 * 考试分数Service业务层处理
 *
 * @author fubojin
 * @date 2025-03-05
 */
@Service
public class ExamFractionServiceImpl implements IExamFractionService
{
    @Autowired
    private ExamFractionMapper examFractionMapper;

    @Autowired
    private ExamWrongMapper examWrongMapper;

    /**
     * 查询考试分数
     *
     * @param id 考试分数主键
     * @return 考试分数
     */
    @Override
    public ExamFraction selectExamFractionById(Long id)
    {
        return examFractionMapper.selectExamFractionById(id);
    }

    /**
     * 查询考试分数列表
     *
     * @param examFraction 考试分数
     * @return 考试分数
     */
    @Override
    public List<ExamFraction> selectExamFractionList(ExamFraction examFraction)
    {
        return examFractionMapper.selectExamFractionList(examFraction);
    }

    /**
     * 新增考试分数
     *
     * @param examFraction 考试分数
     * @return 结果
     */
    @Override
    public int insertExamFraction(ExamFraction examFraction)
    {
        examFraction.setCreateTime(DateUtils.getNowDate());
        int i = examFractionMapper.insertExamFraction(examFraction);
        //添加错题记录
        List<ExamWrong> examWrongList = examFraction.getExamWrongList();
        for (ExamWrong wrong : examWrongList) {
            wrong.setFractionId(examFraction.getId());
            examWrongMapper.insertExamWrong(wrong);
        }
        return i;
    }

    /**
     * 修改考试分数
     *
     * @param examFraction 考试分数
     * @return 结果
     */
    @Override
    public int updateExamFraction(ExamFraction examFraction)
    {
        examFraction.setUpdateTime(DateUtils.getNowDate());
        return examFractionMapper.updateExamFraction(examFraction);
    }

    /**
     * 批量删除考试分数
     *
     * @param ids 需要删除的考试分数主键
     * @return 结果
     */
    @Override
    public int deleteExamFractionByIds(Long[] ids)
    {
        return examFractionMapper.deleteExamFractionByIds(ids);
    }

    /**
     * 删除考试分数信息
     *
     * @param id 考试分数主键
     * @return 结果
     */
    @Override
    public int deleteExamFractionById(Long id)
    {
        return examFractionMapper.deleteExamFractionById(id);
    }
}
